home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ww_tv.exe
/
TEDITOR2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-24
|
18KB
|
761 lines
/*------------------------------------------------------------*/
/* filename - teditor2.cpp */
/* */
/* function(s) */
/* TEditor member functions */
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
/* */
/* Turbo Vision - Version 1.0 */
/* */
/* */
/* Copyright (c) 1991 by Borland International */
/* All Rights Reserved. */
/* */
/*------------------------------------------------------------*/
// Primatech Modification History:
//
// 11-06-91 JLS Removed two apparently useless calls to setBufSize()
// 11-08-91 JLS Put two calls to setBufSize() back in
// 11-12-91 JLS Added code in insertBuffer() to support word wrapping
// 11-19-91 JLS Moved more code into wordWrapBuffer() and modified
// insertBuffer() accordingly
// 07-05-92 JLS Synced with TV1.03 (BC3.10)
// 08-24-92 JLS Added code to write() and read() to handle new member data
//
#define Uses_TKeys
#define Uses_TEditor
#define Uses_TIndicator
#define Uses_TEvent
#define Uses_TScrollBar
#define Uses_TFindDialogRec
#define Uses_TReplaceDialogRec
#define Uses_opstream
#define Uses_ipstream
#include <tv.h>
#if !defined( __STRING_H )
#include <string.h>
#endif // __STRING_H
#if !defined( __CTYPE_H )
#include <ctype.h>
#endif // __CTYPE_H
#if !defined( __DOS_H )
#include <Dos.h>
#endif // __DOS_H
inline int isWordChar( int ch )
{
return isalnum(ch) || ch == '_';
}
#pragma warn -asc
int TEditor::countLines( void *buf, ushort count )
{
asm {
LES DI,buf
MOV CX,count
XOR DX,DX
MOV AL,0Dh
CLD
}
__1:
asm {
JCXZ __2
REPNE SCASB
JNE __2
INC DX
JMP __1
}
__2:
return _DX;
}
ushort scan( const void *block, ushort size, const char *str )
{
ushort len = strlen( str );
asm {
PUSH DS
LES DI,block
LDS SI,str
MOV CX,size
JCXZ __3
CLD
MOV AX,len
CMP AX,1
JB __5
JA __1
LODSB // searching for a single character
REPNE SCASB
JNE __3
JMP __5
}
__1:
asm {
MOV BX,AX
DEC BX
MOV DX,CX
SUB DX,AX
JB __3
LODSB
INC DX
INC DX
}
__2:
asm {
DEC DX
MOV CX,DX
REPNE SCASB
JNE __3
MOV DX,CX
MOV CX,BX
REP CMPSB
JE __4
SUB CX,BX
ADD SI,CX
ADD DI,CX
INC DI
OR DX,DX
JNE __2
}
__3:
asm {
XOR AX,AX
JMP __6
}
__4:
asm SUB DI,BX
__5:
asm {
MOV AX,DI
SUB AX,WORD PTR block
}
__6:
asm {
DEC AX
POP DS
}
return _AX;
}
ushort iScan( const void *block, ushort size, const char *str )
{
char s[256];
ushort len = strlen( str );
asm {
PUSH DS
MOV AX,SS
MOV ES,AX
LEA DI,s
LDS SI,str
MOV AX,len;
MOV CX,AX
MOV BX,AX
JCXZ __9
}
__1:
asm {
LODSB
CMP AL,'a'
JB __2
CMP AL,'z'
JA __2
SUB AL,20h
}
__2:
asm {
STOSB
LOOP __1
SUB DI,BX
LDS SI,block
MOV CX,size
JCXZ __8
CLD
SUB CX,BX
JB __8
INC CX
}
__4:
asm {
MOV AH,ES:[DI]
AND AH,0xDF
}
__5:
asm {
LODSB
AND AL,0xDF
CMP AL,AH
LOOPNE __5
JNE __8
DEC SI
MOV DX,CX
MOV CX,BX
}
__6:
asm {
REPE CMPSB
JE __10
MOV AL,DS:[SI-1]
CMP AL,'a'
JB __7
CMP AL,'z'
JA __7
SUB AL,20h
}
__7:
asm {
CMP AL,ES:[DI-1]
JE __6
SUB CX,BX
ADD SI,CX
ADD DI,CX
INC SI
MOV CX,DX
JNE __4
}
__8:
asm {
XOR AX,AX
JMP __11
}
__9:
asm {
MOV AX, 1
JMP __11
}
__10:
asm {
SUB SI,BX
MOV AX,SI
SUB AX,wORD PTR block
INC AX
}
__11:
asm {
DEC AX
POP DS
}
return _AX;
}
#pragma warn .asc
void TEditor::hideSelect()
{
selecting = False;
setSelect(curPtr, curPtr, False);
}
void TEditor::initBuffer()
{
buffer = new char[bufSize];
}
Boolean TEditor::insertBuffer( char *p,
ushort offset,
ushort length,
Boolean allowUndo,
Boolean selectText,
Boolean alwaysWrap
)
{
selecting = False;
ushort selLen = selEnd - selStart;
if( selLen == 0 && length == 0 && !alwaysWrap )
return True;
ushort delLen = 0;
if( allowUndo == True )
if( curPtr == selStart )
delLen = selLen;
else
if( selLen > insCount )
delLen = selLen - insCount;
long newSize = long(bufLen + delCount - selLen + delLen) + length;
if( newSize > bufLen + delCount )
if( newSize > 0xFFE0l || setBufSize(ushort(newSize)) == False )
{
editorDialog( edOutOfMemory );
return False;
}
ushort selLines = countLines( &buffer[bufPtr(selStart)], selLen );
if( curPtr == selEnd )
{
if( allowUndo == True )
{
if( delLen > 0 )
memmove(
&buffer[curPtr + gapLen - delCount - delLen],
&buffer[selStart],
delLen
);
insCount -= selLen - delLen;
}
curPtr = selStart;
curPos.y -= selLines;
}
if( delta.y > curPos.y )
{
delta.y -= selLines;
if( delta.y < curPos.y )
delta.y = curPos.y;
}
// Insert the text
if (length > 0)
memmove(buffer + curPtr, p + offset, length);
// Change all internal pointers to be correct before calling word-wrap
short lines = countLines(buffer+curPtr, length); // count no. of inserted lines
ushort prevline = prevLine(lineStart(curPtr));
curPtr += length;
bufLen += length - selLen;
gapLen -= length - selLen;
limit.y += lines - selLines;
delta.y = max(0, min(delta.y, limit.y - size.y));
if( allowUndo == True )
{
delCount += delLen;
insCount += length;
}
// The wordWrapBuffer() function might change member data items (curPtr, etc.)
WordWrapState wrap_rc =
wordWrap ? wordWrapBuffer(prevline, curPtr-prevline+1) : wwsNoWrap;
if (wrap_rc == wwsError)
return False;
else if (wrap_rc == wwsNoWrap) {
// If the buffer wrapped, these fields were already adjusted
curPos.y += lines;
drawLine = curPos.y;
drawPtr = lineStart(curPtr);
curPos.x = charPos(drawPtr, curPtr);
}
if (selLines == 0 && lines == 0)
update(ufLine);
else
update(ufView);
if( selectText == False )
selStart = curPtr;
selEnd = curPtr;
// Don't mark clipboard as modified -- it will ask to be saved if it is
if (!isClipboard())
modified = True;
setBufSize(bufLen + delCount); // Shrink buffer to minimum size
return True;
}
Boolean TEditor::insertFrom( TEditor *editor )
{
return insertBuffer( editor->buffer,
editor->bufPtr(editor->selStart),
editor->selEnd - editor->selStart,
canUndo,
isClipboard()
);
}
ushort TEditor: